package io.sage.common.hcnet;

import com.sun.jna.NativeLong;

/**
 * Created by Administrator on 2019/7/17 0017.
 */
public class HcTest {

    public static void main(String[] args) {
        HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
        //加载动态库

//        System.loadLibrary("HCCore");//测试使用
//        System.load("SuperRender.dll");//测试使用
        HCNetSDK.NET_DVR_CLIENTINFO m_strClientInfo = null;
        String m_sDeviceIP = "192.168.4.64";//已登录设备的IP地址
        int iPort = 9999;
        String username = "mafy";
        String password = "123456mafY";
        NativeLong lUserID;//用户句柄
        NativeLong lPreviewHandle;//预览句柄

        boolean initSuc = hCNetSDK.NET_DVR_Init();//设备初始化
        System.out.println("initSuc:"+initSuc);
        lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP, (short) iPort,username,password, null);//登陆
        System.out.println("lUserID,"+lUserID);

        m_strClientInfo = new HCNetSDK.NET_DVR_CLIENTINFO();//预览参数 用户参数
        m_strClientInfo.lChannel = new NativeLong(1);

        lPreviewHandle = hCNetSDK.NET_DVR_RealPlay_V30(lUserID, m_strClientInfo, null, null, true);//播放，窗口句柄在m_strClientInfo里

        System.out.println("error:"+hCNetSDK.NET_DVR_GetLastError());

        System.out.println("lPreviewHandle"+lPreviewHandle);
        System.out.println("m_strClientInfo,"+m_strClientInfo);
        //该处进行录像功能
        boolean a = hCNetSDK.NET_DVR_SaveRealData(lPreviewHandle,"d://b.mp4");
        System.out.println(a);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //此处等待5s
        boolean b = hCNetSDK.NET_DVR_StopSaveRealData(lPreviewHandle);
        System.out.println(b);

        //如果在预览,先停止预览, 释放句柄
        if (lPreviewHandle.longValue() > -1) {
            hCNetSDK.NET_DVR_StopRealPlay(lPreviewHandle);//停止预览
        }
        //如果已经注册,注销
        if (lUserID.longValue() > -1)
        {
            hCNetSDK.NET_DVR_Logout_V30(lUserID);
        }
        hCNetSDK.NET_DVR_Cleanup();
    }
}
